﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageLoanCalculator.aspx.cs" Inherits="InterestCalculation.Calculator" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Laon Calculator</title>
    <script src="../../Scripts/jacs.js"></script>
    <script src="../../Scripts/jquery-1.7.1.min.js"></script>
    <link href="../../Scripts/easyui.css" rel="stylesheet" />
    <link href="../../Scripts/themes/icon.css" rel="stylesheet" />
    <script src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" >
        function calculateLoan(IsUpdate) {
            if (validate()=="") {
                if (!(Is_Date($("#<%=txtFirstRepayment.ClientID%>").val()))) {
                    message("Please enter valid repayment date");
                    return false;
                }
                if (!(Is_Date($("#<%=txtLoanDate.ClientID%>").val()))) {
                    message("Please enter valid loan date")
                    return false;
                }
                clear();
                loading();
                if(IsUpdate=="false")
                {
                    $("#btnUpdate").css("display","none")
                }
                var arr = {
                    "app_id": "12345678",
                    "frequency": "" + $("#<%=ddlFrequency.ClientID%>").val() + "",
                    "principal": "" + $("#<%=txtPrincipal.ClientID%>").val() + "",
                    "LoanDuration": "" + $("#<%=txtLoanDuration.ClientID%>").val() + "",
                    "InterestRate": "" + $("#<%=txtInterestRate.ClientID%>").val() + "",
                    "FirstRepaymentDate": "" + $("#<%=txtFirstRepayment.ClientID%>").val() + "",
                    "LoanDate": "" + $("#<%=txtLoanDate.ClientID%>").val() + "",
                    "OtherCharges": "" + $("#<%=txtOtherCharges.ClientID%>").val() + "",
                    "BrokerageFee": "" + $("#<%=txtBrokerageFee.ClientID%>").val() + "",
                    "CreditSearchFee": "" + $("#<%=txtCreditSearchFee.ClientID%>").val() + "",
                    "EstabalishmentFee": "" + $("#<%=txtEstabalishmentFee.ClientID%>").val() + "",
                    "MonthlyFee": "" + $("#<%=txtMonthlyLoan.ClientID%>").val() + "",
                    "SecurityFee": "" + $("#<%=txtSecurityFee.ClientID%>").val() + "",
                    "LoanType": "" + getLoanType() + "",
                    "IsUpdate":""+IsUpdate+"",
                    "NewRepaymentDate":""+getValue('<%=txtNewPaymentDue.ClientID%>')+"",
                    "NewTerm":""+getValue('<%=txtNewTerm.ClientID%>','d')+"",
                    "NewInterestRate":""+getValue('<%=txtNewInterestRate.ClientID%>','d')+"",
                    "StartDate":""+getValue('<%=txtStartDate.ClientID%>')+"",
                    "Repayment":""+getValue('<%=txtNewRepaymentAmount.ClientID%>','d')+"",
                    "NextRepaymentDue":""+getValue('<%=txtNextRepaymentDue.ClientID%>')+"",
                    "NextFrequency":""+getValue('<%=ddlNextFrequency.ClientID%>','d')+"",
                    "applypayhash":getArrValue('applypayhash'),
                    "SingleRepayment":getArrValue('repayment'),
                    "DesiredACR":getValue('<%=txtDesiredACR.ClientID%>','d')
                };
                $.ajax({
                    url: "/Website Project/Web Method/WebMethodLoanCalculator.ashx?method=calculateLoan",
                    contentType: "application/json; charset=utf-8",
                    type: "POST",
                    datatype: "JSON",
                    data: JSON.stringify(arr),
                    success: function (data) { 
                        writeHTML(data,IsUpdate);
                        loading();
                    },
                    error: function (err) { message(err.responseText); 
                  loading();}
                })
            }else{
                message(validate());
               // alert(validate());
            }
            return false;
        }
        function message(msg)
        {
            $.messager.show({
                title:'Interest Calculator',
                msg:msg,
                showType:'show',
                timeout:0,
                style:{
                    right:'',
                    top:document.body.scrollTop+document.documentElement.scrollTop,
                    bottom:'',
                }
            });
        }
        function getValue(eleId,dtype)
            { 
                var val;
                var type=""; 
                if(typeof(dtype)!=undefined)
                {
                    type=dtype;
                }
                if(type=="d")
                {
                    val=0;
                }else{
                    val="";
                }
                if(document.getElementById(eleId))
                {
                    if(type=="d")
                    {
                        if((!(isNaN($("#"+eleId).val()))) && $("#"+eleId).val()!="")
                        {
                            val=$("#"+eleId).val();
                        }else{
                            val=0;
                        }
                    }else{
                        val=$("#"+eleId).val();
                    }
                }
                return val;
            }
        function getLoanType() {
            var _loanType = "";
            if (document.getElementById("<%=rdbChangeRateTerm.ClientID%>").checked) { _loanType = "ChangeRate"; }
            else if (document.getElementById("<%=rdbChangeAllPayment.ClientID%>").checked) { _loanType = "ChangeAllPayment"; }
            else if (document.getElementById("<%=rdbChangeFrequence.ClientID%>").checked) { _loanType = "ChangeFrequence" }
            else if (document.getElementById("<%=rdbChangeSinglePayment.ClientID%>").checked) { _loanType = "ChangeSinglePayment"; }
            else if (document.getElementById("<%=rdbChangeMaximumRate.ClientID%>").checked) { _loanType = "MaximumInterestRate"; }
            else { _loanType = ""; }
            return _loanType;
        }
        function validate()
        {
            var str="";
            if($('#<%=txtPrincipal.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtPrincipal.ClientID%>').val()))
                {
                    str+="Please enter numeric value in principal amount.</br>";
                }
            }else{
                str+="Please enter principal amount.</br>"
            }
            if($('#<%=txtLoanDuration.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtLoanDuration.ClientID%>').val()))
                   {
                    str+="Please enter numeric value in loan duration.</br>";
                   }
               }else{
                str+="Please enter loan duration.</br>"
            }
            if($('#<%=txtInterestRate.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtInterestRate.ClientID%>').val()))
                {
                    str+="Please enter numeric value in interest.</br>";
                }
            }else{
                str+="Please enter interest.</br>"
            }
            if($('#<%=txtFirstRepayment.ClientID%>').val()=="")
            {
                str+="Please enter first repayment date.</br>";
            }
            if($('#<%=txtLoanDate.ClientID%>').val()=="")
            {
                str+="Please enter loan date.</br>";
            }
            if($('#<%=txtOtherCharges.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtOtherCharges.ClientID%>').val()))
                {
                    str+="Please enter numeric value in interest.</br>";
                }
            }
            if($('#<%=txtBrokerageFee.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtBrokerageFee.ClientID%>').val()))
                {
                    str+="Please enter numeric value in interest.</br>";
                }
            }
            if($('#<%=txtCreditSearchFee.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtCreditSearchFee.ClientID%>').val()))
                {
                    str+="Please enter numeric value in credit search fee.</br>";
                }
            }
            if($('#<%=txtEstabalishmentFee.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtEstabalishmentFee.ClientID%>').val()))
                {
                    str+="Please enter numeric value in estabalishment fee.</br>";
                }
            }
            if($('#<%=txtMonthlyLoan.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtMonthlyLoan.ClientID%>').val()))
                 {
                    str+="Please enter numeric value in monthly loan.</br>";
                 }
            }
            if($('#<%=txtSecurityFee.ClientID%>').val()!="")
            {
                if(isNaN($('#<%=txtSecurityFee.ClientID%>').val()))
                   {
                    str+="Please enter numeric value in security fee.</br>";
                   }
            }
            return str;
        }
        function writeHTML(data,IsUpdate) {
            var totalInterest = 0;
            for (var i = 0; i < data.LoanTable.length; i++)
            {
                if (!(isNaN(data.LoanTable[i].Interest)) && data.LoanTable[i].Interest != null) {
                    totalInterest += parseFloat(data.LoanTable[i].Interest);
                }
            }
            var cdata = [[{ field: "ExtraDay", title: "Extra Days" }, 
                          { field: "nextinterest", title: "Next Interest Date" }, 
                          { field: "repaymentdate", title: "Next Repayment Date"},
                          { field: "Payhash", title: "Pay #"},
                          { field: "date", title: "Date"},
                          { field: "payment", title: "Payment"},
                          {field: "Interest_before_adv", title: "interest"},
                          { field: "advCharges", title: "Adv/Charges"},
                          {field: "Interest", title: "interest"},
                          { field: "balance", title: "Balance"},
                          { field: "discFator", title: "Disc Factor"}
                        ]];
            var LoanData=data.LoanTable;
            $('#result').datagrid({
                columns: cdata,
                data: LoanData
            });
            $("#totalInterest").html(roundUp(totalInterest, 2));
            if (data.DifferenceTable) {
                if (data.DifferenceTable.length > 0) {
                    $("#divDefference").html(roundUp(data.DifferenceTable[0].Difference, 2));
                    $("#divPre_Interest").html(roundUp(data.DifferenceTable[0].PreInterestRate, 2));
                    $("#divEMI").html(roundUp(data.DifferenceTable[0].Pv_EMI, 2));
                    $("#divBalance").html(roundUp(data.DifferenceTable[0].Balance, 2));
                    $("#divInitialInstallment").html(data.DifferenceTable[0].InitialInstallment);
                    $("#divRepaymentLastInstallment").html(roundUp(data.DifferenceTable[0].RepaymentLastInstallment, 2));
                    $("#TotalAmountFunded").html(data.DifferenceTable[0].TotalAmountFunded);
                    $("#LastRepaymentDate").html(data.DifferenceTable[0].LastRepaymentDate);
                    $("#NoOfInstallment").html(data.DifferenceTable[0].NoofInstallment);
                    $("#repayment").html(data.DifferenceTable[0].Repayment);
                    $("#divSimpleInterest").html(data.DifferenceTable[0].SimpleInterest);
                }
            }
            if (data.RateChange) {
                var cdata = [[{ field: "Description", title: "" }, 
                         { field: "ChangeRate", title: "Change Rate" }, 
                         { field: "ChangeFreq", title: "Change Freq"},
                         { field: "ChangeRepmt", title: "Change Repmt"},
                         { field: "SinglePmt", title: "Single Pmt"}
                ]];
                var changeRate=data.RateChange;
                $("#ratechange").datagrid({
                    columns: cdata,
                    data: changeRate
                });
            }
            if (data.InterestTable) {
                if (data.InterestTable.length > 0) {
                    $("#divInterest").html(roundUp(convertToPercentage(data.InterestTable[0].Interest), 8) + "%");
                    $("#divComparisonRate").html(roundUp(convertToPercentage(data.InterestTable[0].ComparisonRate), 8) + "%");
                    $("#divTrialRate").html(roundUp(convertToPercentage(data.InterestTable[0].TrailRate), 8) + "%");
                    $("#divRivisedPayment").html(roundUp(data.InterestTable[0].RevisedRepayment, 2));
                    $("#ComparisonRate").html(roundUp(convertToPercentage(data.InterestTable[0].ComparisonRate), 8) + "%");
                    var _table='<table cellpadding="0" cellspacing="0" border="1" style="border-collapse:collapse" width="80%">'
                    _table+='<tr>';
                    _table+='<td>Present ACR</td>';
                    _table+='<td><div id="PresentACR">'+roundUp(convertToPercentage(data.InterestTable[0].ComparisonRate), 2) + '%</div></td>';
                    _table+='</tr>';
                    _table+='<tr>';
                    _table+='<td>Desired ACR</td>';
                    _table+='<td><div id="DesiredACR">48%</div></td>';
                    _table+='</tr>';
                    _table+='<tr>';
                    _table+='<td>Maximum Interest</td>';
                    _table+='<td><div id="MaximumInterest">'+roundUp(convertToPercentage(data.InterestTable[0].Interest), 4) + '%</div></td>';
                    _table+='</tr>';
                    _table+='<tr>';
                    _table+='<td>Revised Repayment</td>';
                    _table+='<td><div id="RevisedRepayment">'+roundUp(data.InterestTable[0].RevisedRepayment, 2)+'</div></td>';
                    _table+='</tr>';
                    _table+='</table>';
                }
            }
            
            if (data.Output) {
                var cdata = [[  { field: "blank", title: ""},
                        { field: "CurrentBalance", title: "Current Balance" }, 
                        { field: "InterestRate", title: "Interest Rate" }, 
                        { field: "RepaymentFrequency", title: "Repayment Frequency"},
                        { field: "RepaymentAmount", title: "Repayment Amount"},
                        { field: "RepaymentRemaining", title: "# Repayments Remaining"}
                ]];
                var output=data.Output;
                if(getLoanType()=="ChangeRate")
                {
                    if(IsUpdate=="false")
                    {
                        $("#Output").datagrid({
                            columns: cdata,
                            data: output
                        });
                        Display('changeRate');
                        if(data.OutputParameter)
                            {
                            $("#<%=txtNewPaymentDue.ClientID%>").val(data.OutputParameter[0].NewPaymentDue);
                            $("#<%=txtNewInterestRate.ClientID%>").val(data.OutputParameter[0].NewInterestRate);
                            $("#<%=txtNewTerm.ClientID%>").val(data.OutputParameter[0].NewTerm);
                            }
                    
                    }else{
                        $("#UpdateOutput").datagrid({
                            columns: cdata,
                            data: output
                        });
                    } 
                    $("#btnUpdate").css("display","block")
                }else if (getLoanType()=="ChangeAllPayment")
                {
                    if(IsUpdate=="false")
                    {
                        $("#Output").datagrid({
                            columns: cdata,
                            data: output
                        });
                        Display('ChanageAllPayment');
                        if(data.OutputParameter)
                        {
                            $("#<%=txtStartDate.ClientID%>").val(data.OutputParameter[0].startdate);
                            $("#<%=txtNewRepaymentAmount.ClientID%>").val(data.OutputParameter[0].newpaymentdue);
                        }
                    }else{
                        $("#UpdateOutput").datagrid({
                            columns: cdata,
                            data: output
                        });
                    } 
                    $("#btnUpdate").css("display","block")
                }else if (getLoanType()=="ChangeFrequence")
                {
                    if(IsUpdate=="false")
                    {
                       
                        $("#Output").datagrid({
                            columns: cdata,
                            data: output
                        });
                        Display('ChangeFrequence');
                        if(data.OutputParameter)
                        {
                            $("#<%=ddlNextFrequency.ClientID%>").val(data.OutputParameter[0].NewFrequency);
                            $("#<%=txtNextRepaymentDue.ClientID%>").val(data.OutputParameter[0].newpaymentdue);
                        }
                    }else{
                        $("#UpdateOutput").datagrid({
                            columns: cdata,
                            data: output
                        });
                    } 
                    $("#btnUpdate").css("display","block")
                }else if (getLoanType()=="ChangeSinglePayment")
                {
                    if(IsUpdate=="false")
                    {
                        var lastIndex;
                        $("#Output").datagrid({
                            columns: cdata,
                            data: output,
                        });
                        var _singlrpaymentHTML='';
                        if(data.singlepayment)
                        {
                            for(var i=0;i<data.singlepayment.length;i++)
                            {
                                var _input='';
                                var _payhash='';
                                if(i>0){
                                    _input="<input type='text' style='width:50px' value='"+data.singlepayment[i].RepaymentRemaining+"' name='repayment' />";
                                    _payhash="<input type='hidden' name='applypayhash' value='"+data.singlepayment[i].CurrentBalance+"' />";
                                }
                                _singlrpaymentHTML+="<tr><td>"+data.singlepayment[i].CurrentBalance+"</td><td>"+data.singlepayment[i].InterestRate+"</td><td>"+data.singlepayment[i].RepaymentFrequency+"</td><td>"+data.singlepayment[i].RepaymentAmount+"</td><td>"+_input+_payhash+"</td><td>&nbsp;</td></tr>"
                            }
                        }
                        $("#output_data table.datagrid-btable").append(_singlrpaymentHTML);
                        Display('');
                    } else{
                        $("#UpdateOutput").datagrid({
                            columns: cdata,
                            data: output
                        });
                    } 
                }
                else if (getLoanType()=="MaximumInterestRate")
                {
                    if(IsUpdate=="false")
                    {
                        $("#output_data").html("<div id='Output'></div>");
                        Display('maximuminterestrate');
                        if(data.Output)
                        {
                            if (data.Output) {
                                if (data.Output.length > 0) {
                                    $("#<%=txtPresentACR.ClientID%>").val(roundUp(convertToPercentage(data.Output[0].PresentACR), 2));
                                    $("#<%=txtDesiredACR.ClientID%>").val(0);
                                    $("#<%=txtMaximumInterest.ClientID%>").val(0);
                                    $("#<%=txtRevisedRepayment.ClientID%>").val(0);
                                }
                            }
                        }
                    }else{
                        if(data.Output)
                        {
                            if (data.Output) {
                                if (data.Output.length > 0) {
                                    $("#<%=txtPresentACR.ClientID%>").val(roundUp(convertToPercentage(data.Output[0].PresentACR), 8));
                                    $("#<%=txtDesiredACR.ClientID%>").val(data.Output[0].DesiredACR);
                                    $("#<%=txtMaximumInterest.ClientID%>").val(data.Output[0].MaximumInterest);
                                    $("#<%=txtRevisedRepayment.ClientID%>").val(data.Output[0].RevisedRepayment);
                                }
                            }
                        }
                    } 
                }   
                 $("#btnUpdate").css("display","block")
                }
            }
        function getArrValue(name)
        {
            var arr=new Array();
            $("input[name='"+name+"']").each(function(){
               arr.push($(this).val());
            })
            if(arr.length==0)
            {
                arr.push(0);
            }
            return arr;
        }
        function Display(id)
        {
            $("#ChanageAllPayment").css("display","none"); 
            $("#changeRate").css("display","none");
            $("#ChangeFrequence").css("display","none"); 
            $("#maximuminterestrate").css("display","none"); 
            $("#"+id).css("display","block"); 
        }
        function convertToPercentage(val) {
            var _tempval = 0;
            if (!(isNaN(val))) {
                _tempval = parseFloat(val) * 100;
            }
            return _tempval;
        }
        function convertToDate(jsonDate) {
            var date = "";
            if (jsonDate != "" && jsonDate != null) {
                var value = new Date(parseInt(jsonDate.substr(6)));
                date= value.getDate()+ "/"+ placeZero((value.getMonth() + 1))+ "/" + value.getFullYear();
            }
            return date;
        }
        function placeZero(month)
        {
            if(month.toString().length==1)
            {
                return month="0"+month;
            }else{
                return month;
            }
        }
        function roundUp(val, decimalplace) {
            var _mulVar = 1;
            switch (decimalplace) {
                case 1:
                    _mulVar = 10;
                    break;
                case 2:
                    _mulVar = 100;
                    break;
                case 3:
                    _mulVar = 1000;
                    break;
                case 4:
                    _mulVar = 10000;
                    break;
                case 5:
                    _mulVar = 100000;
                    break;
                case 6:
                    _mulVar = 1000000;
                    break;
                case 7:
                    _mulVar = 10000000;
                    break;
                case 8:
                    _mulVar = 100000000;
                    break;

            }
            var _roundValue = 0;
            if (!(isNaN(val))) {
                _roundValue = Math.round(parseFloat(val) * parseFloat(_mulVar)) /parseInt(_mulVar);
            }
            return _roundValue;
        }
        function clear() {
            $("#result").html("");
            $("#totalInterest").html("");
            $("#divDefference").html("");
            $("#divPre_Interest").html("");
            $("#divEMI").html("");
            $("#divBalance").html("");
            $("#divInitialInstallment").html("");
            $("#divRepaymentLastInstallment").html("");
            $("#TotalAmountFunded").html("");
            $("#LastRepaymentDate").html("");
            $("#NoOfInstallment").html("");
            $("#repayment").html("");
            $("#divSimpleInterest").html("");
            $("#divInterest").html("");
            $("#divComparisonRate").html("");
            $("#divTrialRate").html("");
            $("#divRivisedPayment").html("");
            $("#ComparisonRate").html("");
            $("#ratechange").html("");
            $("#UpdateOutput").html("");
            
        }
        function checkValidInput(ele) {
            if (ele.value.trim() != "") {
                if (isNaN(ele.value)) {
                    ele.value = 0;
                }
            } else {
                ele.value = 0;
            }
        }
        function loading() {
            if ($("#loading").html() == "") {
                $("#loading").html("<img src='/Images/load.gif' alt='Loading...' />");
            } else {
                $("#loading").html("");
            }
        }
        function Is_Date(dt){
            var tdate = new Date();
            splitDate = dt.split("/");
            refDate = new Date(splitDate[1]+ "/" + splitDate[0]+"/"+splitDate[2]);
            if (splitDate[1] < 1 || splitDate[1] > 12 || refDate.getDate() != splitDate[0] || splitDate[2].length != 4)
            {
                return false;
            }else{
                if(splitDate[2]<(tdate.getFullYear() -100) || splitDate[2]>(tdate.getFullYear() +100)){
                    return false;
                }else{
                    return true;
                }
            }
        }
    </script>
    <style type="text/css">
        .red {
            color:red;
        }
        .hide {
            display:none; 
        }
        .show {
            display:block;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table cellpadding="5"  cellspacing="0" >
            <tr>
                <td colspan="2" style="text-align:center">Loan Calculator</td>
            </tr>
            <tr>
                <td>Select Frequency</td>
                <td><asp:DropDownList ID="ddlFrequency" runat="server" >
                    <asp:ListItem Text="Weekly" Value="0"></asp:ListItem>  
                    <asp:ListItem Text="Fortnighty" Value="1"></asp:ListItem>  
                    <asp:ListItem Text="Monthly" Value="2"></asp:ListItem>  
                </asp:DropDownList></td>
            </tr>
            <tr>
                <td>Principal</td>
                <td>
                    <asp:TextBox ID="txtPrincipal" runat="server" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Loan Duration (in week)</td>
                <td>
                    <asp:TextBox ID="txtLoanDuration" runat="server" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Interest Rate</td>
                <td><asp:TextBox ID="txtInterestRate" runat="server" ></asp:TextBox>
                </td>

            </tr><tr>
                <td>Loan Date</td>
                <td><asp:TextBox ID="txtLoanDate" runat="server" ></asp:TextBox>&nbsp;
                    <input name="btnLoanDate" value="+" id="btnLoanDate" type="button"  onclick="JACS.show(document.getElementById('<%=txtLoanDate.ClientID %>'),event);" /> 
                </td>
            </tr>
            <tr>
                <td>First Repayment Date</td>
                <td><asp:TextBox ID="txtFirstRepayment" runat="server" ></asp:TextBox>
                   <input name="btnLoanDate" value="+" id="btnFirstRepayment" type="button"  onclick="JACS.show(document.getElementById('<%=txtFirstRepayment.ClientID %>'),event);" /> 
                </td>
            </tr>
            <tr>
                <td>Other Charges </td>
                <td><asp:TextBox ID="txtOtherCharges" runat="server" Text="0" onblur="checkValidInput(this);" onchnage="checkValidInput(this);" ></asp:TextBox>
                </td>
            </tr>
             <tr>
                <td>Brokerage Fee</td>
                <td><asp:TextBox ID="txtBrokerageFee" runat="server" Text="0" onchnage="checkValidInput(this);"  ></asp:TextBox>
                </td>
            </tr>
             <tr>
                <td>Credit Search Fee</td> 
                <td><asp:TextBox ID="txtCreditSearchFee" runat="server" Text="0" onchnage="checkValidInput(this);" ></asp:TextBox>
                </td>
            </tr>
             <tr>
                <td>Estabalishment  Fee </td>
                <td><asp:TextBox ID="txtEstabalishmentFee" runat="server" Text="0" onchnage="checkValidInput(this);" ></asp:TextBox>
                </td>
            </tr>
                <tr>
                <td>Monthly Loan Service Fee</td>
                <td><asp:TextBox ID="txtMonthlyLoan" runat="server" Text="0" onchnage="checkValidInput(this);" ></asp:TextBox>
                </td>
            </tr>
                <tr>
                <td>Security Registration Fee</td>
                <td><asp:TextBox ID="txtSecurityFee" runat="server" Text="0" onchnage="checkValidInput(this);" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:RadioButton ID="rdbChangeRateTerm" runat="server" ValidationGroup="cal"   GroupName="g" Text="Change Rate/Term"   /> 
                    <asp:RadioButton ID="rdbChangeAllPayment" runat="server" ValidationGroup="cal"  GroupName="g" Text="Change All Payments"   /> 
                    <asp:RadioButton ID="rdbChangeFrequence" runat="server" ValidationGroup="cal"  GroupName="g" Text="Change Frequency"   /> 
                    <asp:RadioButton ID="rdbChangeSinglePayment" runat="server" ValidationGroup="cal"  GroupName="g" Text="Change Single Payment"   /> 
                    <asp:RadioButton ID="rdbChangeMaximumRate" runat="server" ValidationGroup="cal"  GroupName="g" Text="Maximum Interest Rate"   /> 
                 <!--   <asp:RadioButton ID="rdbMaxinterest" runat="server" Checked="true"  ValidationGroup="cal" onchange="return calculateLoan('false');" GroupName="g" Text="Maximum Interest Rate"   /> -->
                </td>
            </tr>
            <tr>
                <td colspan="2">
                   <div style="float:left; width:120px"><div style="float:left"><asp:Button ID="btnCalculate" runat="server" OnClientClick="return calculateLoan('false');" ValidationGroup="cal"  Text="Calculate" /></div><div style="float:left"></div></div>
                    <div style="float:left" id="loading"></div>
                </td>
            </tr>
            <tr>
                 <td colspan="2" >
                     <div id="output_data">
                         <div id="Output">
                         </div>
                      </div>
                     <div>
                         <table id="changeRate" cellpadding="5" cellspacing="0" style="display:none">
                             <tr>
                                 <td>New Payment Due</td>
                                 <td><asp:TextBox ID="txtNewPaymentDue" runat="server" ></asp:TextBox>
                                     <input name="btnNewPaymentDue" value="+" id="btnNewPaymentDue" type="button"  onclick="JACS.show(document.getElementById('<%=txtNewPaymentDue.ClientID %>'),event);" /> 
                                 </td>
                             </tr>
                             <tr>
                                 <td>New Interest Rate</td>
                                 <td><asp:TextBox ID="txtNewInterestRate" runat="server" ></asp:TextBox>
                                 </td>
                             </tr>
                             <tr>
                               
                                 <td>New Term</td>
                                 <td><asp:TextBox ID="txtNewTerm" runat="server" ></asp:TextBox>
                                 </td>
                             </tr>
                            
                         </table>
                         <table id="ChanageAllPayment" cellpadding="5" cellspacing="0" style="display:none">
                             <tr>
                                 <td>Start Date</td>
                                 <td><asp:TextBox ID="txtStartDate" runat="server" ></asp:TextBox>
                                     <input name="btnStartDate" value="+" id="btnStartDate" type="button"  onclick="JACS.show(document.getElementById('<%=txtStartDate.ClientID %>    '),event);" /> 
                                 </td>
                             </tr>
                             <tr>
                                 <td>New Repayment Amount</td>
                                 <td><asp:TextBox ID="txtNewRepaymentAmount" runat="server" ></asp:TextBox>
                                 </td>
                             </tr>
                         </table>
                       
                          <table id="ChangeFrequence" cellpadding="5" cellspacing="0" style="display:none">
                            <tr>
                                <td>Next Frequency</td>
                                    <td><asp:DropDownList ID="ddlNextFrequency" runat="server" >
                                            <asp:ListItem Text="Weekly" Value="0"></asp:ListItem>  
                                            <asp:ListItem Text="Fortnighty" Value="1"></asp:ListItem>  
                                            <asp:ListItem Text="Monthly" Value="2"></asp:ListItem>  
                                        </asp:DropDownList>
                                </td>
                            </tr>
                             <tr>
                                 <td>Next Repayment Due</td>
                                 <td><asp:TextBox ID="txtNextRepaymentDue" runat="server" ></asp:TextBox>
                                     <input name="btnStartDate" value="+" id="Button1" type="button"  onclick="JACS.show(document.getElementById('<%=txtNextRepaymentDue.ClientID %>'),event);" /> 
                                 </td>
                             </tr>
                         </table>
                          <table cellpadding="5" cellspacing="0" id="maximuminterestrate" style="display:none" >
                              <tr>
                                  <td colspan="2">Output</td>
                              </tr>
                              <tr>
                                  <td>Present ACR</td>
                                  <td><asp:TextBox ID="txtPresentACR" runat="server" Text="0"></asp:TextBox></td>
                              </tr>
                              <tr>
                                  <td>Desired ACR</td>
                                  <td><asp:TextBox ID="txtDesiredACR" runat="server" Text="0"></asp:TextBox></td>
                              </tr>
                              <tr>
                                  <td>Maximum Interest</td>
                                  <td><asp:TextBox ID="txtMaximumInterest" runat="server" Text="0"></asp:TextBox></td>
                              </tr>
                              <tr>
                                  <td>Revised Reapyment</td>
                                  <td><asp:TextBox ID="txtRevisedRepayment" runat="server" Text="0"></asp:TextBox></td>
                              </tr>
                          </table>
                      
                           <table id="btnUpdate" cellpadding="5" cellspacing="0" style="display:none">
                             <tr>
                                 <td>
                                     <asp:Button ID="btnSubmit" runat="server"  OnClientClick="return calculateLoan('true');" ValidationGroup="newcal"  Text="Update" />            
                                 </td>
                             </tr> 
                          </table> 
                     </div>
                     <div id="UpdateOutput">
                         
                     </div>
                     <div>
                         <table cellpadding="5" cellspacing="0" width="80%" border="1" style="border-collapse:collapse">
                             <tr>
                                 <th colspan="2">Output</th>
                             </tr>
                             <tr>
                                 <td>Total Amount Funded</td>
                                 <td><div id="TotalAmountFunded"></div></td>
                             </tr>
                             <tr>
                                 <td>Last Repayment Date</td>
                                 <td><div id="LastRepaymentDate"></div></td>
                             </tr>
                              <tr>
                                 <td>No of Installment</td>
                                 <td><div id="NoOfInstallment"></div></td>
                             </tr>
                             <tr>
                                 <td>Repayment</td>
                                 <td><div id="repayment"></div></td>
                             </tr>
                             <tr>
                                 <td>Total Interest</td>
                                 <td><div id="totalInterest"></div></td>
                             </tr>
                             <tr>
                                 <td>Comparison Rate</td>
                                 <td><div id="ComparisonRate"></div></td>
                             </tr>
                         </table>
                     </div>
                     <div>
                         <table cellpadding="5" cellspacing="0" width="80%" border="1" style="border-collapse:collapse">
                             <tr>
                                 <th colspan="2">Output</th>
                             </tr>
                             <tr>
                                 <td>Simple Interest</td>
                                 <td><div id="divSimpleInterest"></div></td>
                             </tr>
                             <tr>
                                 <td>Pre-First Repayment Interest</td>
                                 <td><div id="divPre_Interest"></div></td>
                             </tr>
                              <tr>
                                 <td>Initial Installment</td>
                                 <td><div id="divInitialInstallment"></div></td>
                             </tr>
                             <tr>
                                 <td>Balance</td>
                                 <td><div id="divBalance"></div></td>
                             </tr>
                              <tr>
                                 <td>Repayment-Last Installment</td>
                                 <td><div id="divRepaymentLastInstallment"></div></td>
                             </tr>
                              <tr>
                                 <td>Difference</td>
                                 <td><div id="divDefference"></div></td>
                             </tr>
                               <tr>
                                 <td>PV of EMIs</td>
                                 <td><div id="divEMI"></div></td>
                             </tr>
                              <tr>
                                 <td>Revised Repayment</td>
                                 <td><div id="divRivisedPayment"></div></td>
                             </tr>
                              <tr>
                                 <td>Trial rate for Comp Intt rate</td>
                                 <td><div id="divTrialRate"></div></td>
                             </tr>
                         </table>
                       </div>
                     <div>
                         <table cellpadding="5" cellspacing="0" width="80%" border="1" style="border-collapse:collapse">
                             <tr>
                                 <th colspan="2">Output</th>
                             </tr>
                             <tr>
                                 <td> Comparison Rate</td>
                                 <td><div id="divComparisonRate"></div></td>
                             </tr>
                             <tr>
                                 <td>Interest</td>
                                 <td><div id="divInterest"></div></td>
                             </tr>
                             </table>
                      </div>
                    
                    <%-- <div id="ratechange">
                     </div>--%>
                     <table id="ratechange"></table>
                    <%-- <div id="result"></div>--%>
                     <table id="result"></table>
                 </td>   
            </tr>
        </table>  

    </div>
    </form>
</body>
</html>
